home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk3 / structures / macros.opt < prev    next >
Text File  |  1995-03-18  |  13KB  |  669 lines

  1. **************************************************************** 
  2. * NOTES: Include this file where the subroutines are to go. 
  3. *     This way, the subroutines and macros may be 
  4. *     kept together in this file.
  5. ****************************************************************
  6.  
  7. *----- EQUATES -----*
  8.  
  9. AbsBase    EQU    4
  10.  
  11. *-------------------*
  12.  
  13.     SECTION CODE
  14.  
  15.     IFD libs
  16.  
  17.     XTRN    OpenLibrary
  18.     XTRN    CloseLibrary
  19.  
  20. *************************************************
  21. *  Leave program after closing all open libraries
  22. *************************************************
  23.  
  24. exit    MACRO        ;leave program with return code \1
  25.     move.l    \1,d2
  26.     jmp    do.close
  27.     ENDM
  28.  
  29. *******************************************
  30. * Open all libraries specified by USE macro
  31. *******************************************
  32.  
  33. dolibs    MACRO
  34.     jsr    do.libs
  35.     ENDM
  36.  
  37. *************************************************
  38. * Miscellaneous macros called by EXIT and DOLIBS
  39. *************************************************
  40.  
  41. openlib    MACRO            ;opens an individual library
  42.     lea    \1,a1        ;name of library
  43.     bsr    openit
  44.     move.l    d0,\2        ;store pointer
  45.     ENDM
  46.  
  47. closelib MACRO
  48.     move.l    \1,a1        ;pointer to library
  49.     bsr    closeit
  50.     ENDM
  51.  
  52. setlib    MACRO
  53.     move.l    \1,a6        ;pointer to library
  54.     ENDM
  55.  
  56. ********************************
  57. *  Open all pertinent libraries
  58. ********************************
  59.     CNOP    0,4
  60.  
  61. do.libs
  62.     IFD    doslib
  63.     openlib    dosname,dos
  64.     beq    exitlib
  65.     ENDC
  66.  
  67.     IFD    intlib
  68.     openlib    intname,int
  69.     beq    exitlib
  70.     ENDC
  71.  
  72.     IFD    gfxlib
  73.     openlib    gfxname,gfx
  74.     beq    exitlib
  75.     ENDC
  76.  
  77.     IFD    dfontlib
  78.     openlib    dfontname,dfont
  79.     beq    exitlib
  80.     ENDC
  81.  
  82.     IFD    clistlib
  83.     openlib    clistname,clist
  84.     beq    exitlib
  85.     ENDC
  86.  
  87.     IFD    layerslib
  88.     openlib    layersname,layers
  89.     beq    exitlib
  90.     ENDC
  91.  
  92.     IFD    ffplib
  93.     openlib    ffpname,ffp
  94.     ENDC
  95.  
  96.     IFD    translib
  97.     openlib    transname,trans
  98.     ENDC
  99.  
  100.     IFD    mathdoublib
  101.     openlib    doublename,double
  102.     ENDC
  103.  
  104.     IFD    speechlib
  105.     openlib    speechname,speech
  106.     ENDC
  107.  
  108.     IFD    iconlib
  109.     openlib    iconname,icon
  110.     ENDC
  111.  
  112. exitlib    rts
  113.  
  114. ************************************************************************
  115. *  Close all libraries.
  116. *  NOTE: JSR to this routine if you want to close all libraries and do
  117. *     some more stuff in the main program. 
  118. *     If you want to leave the progam, use the 'exit' MACRO, and
  119. *     call with a return code, ie. EXIT 0   ;(good return)
  120. ************************************************************************
  121.  
  122. do.close
  123.     IFD    doslib
  124.     tst.l    dos
  125.     beq    close1
  126.     closelib dos
  127. close1
  128.     ENDC
  129.  
  130.     IFD    intlib
  131.     tst.l    int
  132.     beq    close2
  133.     closelib int
  134. close2
  135.     ENDC
  136.  
  137.     IFD    gfxlib
  138.     tst.l    gfx
  139.     beq    close3
  140.     closelib gfx
  141. close3
  142.     ENDC
  143.  
  144.     IFD    dfontlib
  145.     tst.l    dfont
  146.     beq    close4
  147.     closelib dfont
  148. close4
  149.     ENDC
  150.  
  151.     IFD    clistlib
  152.     tst.l    clist
  153.     beq    close5
  154.     closelib clist
  155. close5
  156.     ENDC
  157.  
  158.     IFD    layerslib
  159.     tst.l    layers
  160.     beq    close6
  161.     closelib layers
  162. close6
  163.     ENDC
  164.  
  165.     IFD    ffplib
  166.     tst.l    ffp
  167.     beq    close7
  168.     closelib ffp
  169. close7
  170.     ENDC
  171.  
  172.     IFD    translib
  173.     tst.l    trans
  174.     beq    close8
  175.     closelib trans
  176. close8
  177.     ENDC
  178.  
  179.     IFD    mathdoublib
  180.     tst.l    double
  181.     beq    close9
  182.     closelib double
  183. close9
  184.     ENDC
  185.  
  186.     IFD    speechlib
  187.     tst.l    speech
  188.     beq    close10
  189.     closelib speech
  190. close10
  191.     ENDC
  192.  
  193.     IFD    iconlib
  194.     tst.l    icon
  195.     beq    close11
  196.     closelib icon
  197. close11
  198.     ENDC
  199.  
  200.     move.l    d2,d0
  201.     rts
  202.  
  203. ***********************************
  204. * Openit. Opens a library
  205. ************************************
  206.  
  207. openit    clr.l    d0
  208.     move.l    AbsBase,a6
  209.     call    OpenLibrary(a6)
  210.     rts
  211.  
  212. ****************************************************************
  213. *  Subroutine called by EXIT to close libraries.
  214. *  NOTE: Closes only those libraries that have been
  215. *        opened by your program.
  216. ****************************************************************
  217.  
  218. closeit    move.l    AbsBase,a6
  219.     call    CloseLibrary(a6)
  220.     rts
  221.  
  222.     ENDC        ;libs
  223.  
  224. ***********************************************************************
  225. *
  226. *            binhex
  227. *
  228. * PURPOSE: Convert a binary value in a register to 
  229. *       a hex ASCII string at the destination address
  230. *          
  231. * ROUTINE TYPE: MACRO with SUBROUTINE
  232. *
  233. * SYNTAX: binhex    source(long),destination
  234. *      binhexw    source(word),destination
  235. *      binhexb    source(byte),destination
  236. *
  237. * ENTRY CONDITIONS: None
  238. *
  239. * RETURNS: ASCII string in destination address
  240. *       NOTE: destination is 8 bytes long to hold string
  241. *             for any length (long, word, byte).
  242. *             Destination contains result padded with leading zeros.
  243. *
  244. * CHANGED: Nothing
  245. *
  246. * USAGE: binhex    #label,address    ;converts the address at label to 
  247. *                ;string at address
  248. *     binhex    label,address    ;conv contents at label
  249. *
  250. *     binhex #value,address    ;convert immediate value
  251. *
  252. ****************************************************************
  253.  
  254.     IFD    b2h
  255.  
  256. binhexb     MACRO        ;convert a single byte
  257.     clr.l    d0
  258.     move.b    \1,d0
  259.     lea    \2,a0
  260.     jsr    bin2hex
  261.     ENDM
  262.  
  263. binhexw     MACRO        ;convert 2 byte value
  264.     clr.l    d0
  265.     move.w    \1,d0
  266.     lea    \2,a0
  267.     jsr    bin2hex
  268.     ENDM
  269.  
  270. binhex    MACRO        ;convert 4 byte value
  271.     move.l    \1,d0
  272.     lea    \2,a0        ;address of destination
  273.     jsr bin2hex
  274.     ENDM
  275.  
  276. bin2hex move.l    a0,-(sp)
  277.     move.l    d2,-(sp)    ;preserve d2
  278.     move.l    #7,d2        ;count to d2
  279.     clr.l    d1        ;conversion work register
  280.  
  281. bhloop    rol.l    #4,d0        ;get high order nybble to low order
  282.     move.b    d0,d1        ;low order byte to d1
  283.     andi.b    #$f,d1        ;isolate low order nybble
  284.     cmp.b    #$0a,d1        ;digit or letter?
  285.     blt.s    bhaddz        ;branch if digit
  286.     add.b    #'A'-'0'-$0A,d1    ;offset for letters
  287.  
  288. bhaddz    add.b    #'0',d1        ;convert to ASCII
  289.     move.b    d1,(a0)+    ;store it and increment address
  290.     dbf    d2,bhloop    ;do 8 times
  291.  
  292.     move.l    (sp)+,d2    ;restore d2
  293.     move.l    (a7)+,a0    ;restore a0
  294.     rts
  295.  
  296.     ENDC            ;b2h
  297.  
  298. **********************************************************************
  299. *
  300. *            print, printz
  301. *
  302. * PURPOSE: Print a string
  303. *
  304. * ROUTINE TYPE: MACRO
  305. *
  306. * SYNTAX: print <string pointer>,<length of string>
  307. *         printz <pointer to NULL terminated string>
  308. *
  309. * ENTRY CONDITIONS: <setlib dos> required
  310. *            Must have screen handle in stdout
  311. *
  312. * RETURNS: None
  313. *
  314. * USAGE: print message,length
  315. *
  316. **********************************************************************
  317.  
  318.     IFD    prt
  319.     use scnnull        ;include scan for null macro
  320.  
  321. print    MACRO
  322.     move.l    stdout,d1
  323.     move.l    \1,d2        ;NOTE: Needs full addressing mode in args
  324.     move.l    \2,d3
  325.     call    Write(a6)
  326.     ENDM
  327.  
  328. printz    MACRO            ;print NULL terminated string
  329.     move.l    stdout,d1
  330.     move.l    \1,d2        ;address of string
  331.     move.l    d2,a0        ;to a0 for calculation
  332.     bsr    scanull        ;count length to first NULL
  333.     call    Write(a6)
  334.     ENDM
  335.  
  336.     ENDC            ;prt
  337.  
  338.     IFD    scnnull
  339. scanull    move.l    #-1,d3        ;preset for proper count
  340. scnuloop:
  341.     add.l    #1,d3        ;count times through here
  342.     cmp.b    #0,(a0)+    ;compare and increment
  343.     bne.s    scnuloop    ;go try next
  344.     rts            ;or leave with count in d3 fo Write
  345.     ENDC
  346.  
  347.  
  348.  
  349. **********************************************************************
  350. *
  351. *            copy
  352. *
  353. * PURPOSE: MACRO with SUBROUTINE
  354. *
  355. * ROUTINE TYPE: MACRO with SUBROUTINE
  356. *
  357. * SYNTAX: copyb <source address>,<dest address>
  358. *
  359. * USAGE: copyb label,label2,#length  (addressing mode passed for length)
  360. *
  361. **********************************************************************
  362.  
  363.     IFD    copy
  364.  
  365. copyb    MACRO
  366.     lea    \1,a0
  367.     lea    \2,a1
  368.     move.l    \3,d0
  369.     jsr    docopy
  370.     ENDM
  371.     
  372. docopy    subq.l    #1,d0
  373. coploop    move.b    0(a0,d0),0(a1,d0)
  374.     dbf    d0,coploop
  375.     rts
  376.  
  377.     ENDC
  378.  
  379. **********************************************************************
  380. *
  381. *            instr
  382. *
  383. * PURPOSE: MACRO with SUBROUTINE
  384. *
  385. * ROUTINE TYPE: MACRO with SUBROUTINE
  386. *
  387. * SYNTAX: instr <address of string>,<address of string>,terminator
  388. *
  389. * ENTRY CONDITIONS: None
  390. *
  391. * RETURNS: D0 = position of string 1 in string2
  392. *            or -1 if string1 not in string2
  393. *
  394. * USAGE: instr    string1,string2,13    ;terminator is C/R
  395. *     cmp.b    #-1,d0
  396. *     beq    nomatch            ;string1 not in string2
  397. *     move.l    d0,position        ;save position if needed
  398. *
  399. **********************************************************************
  400.  
  401.     IFD    ins
  402.     use    sln
  403.     use    scm
  404.  
  405. instr    MACRO
  406.     move.l    \1,a0        ;string 1
  407.     move.l    \2,a1        ;string 2
  408.     move.l    #\3,d0        ;terminator
  409.     jsr    instrn
  410.     ENDM
  411.  
  412. instrn    movem.l    d1/a0-a1,-(sp)    ;preserve addresses and d1
  413.     pushl    a1        ;for later calculation of position
  414.     move.l    d0,d1        ;terminator to d1
  415.  
  416. inloop    bsr.s    strcomp        ;go check for match
  417.     beq.s    isin        ;got a match
  418.  
  419.     adda.l    #1,a1        ;adjust string 2 address
  420.  
  421.     cmp.b    -1(a1),d0    ;check for terminator
  422.     bne.s    inloop        ;go try again
  423.  
  424. isntin    move.l    #-1,d0        ;-1 indicates str1 not in str2
  425.     popl    a1        ;adjust stack
  426.  
  427.     bra.s    insexit        ;leave
  428.  
  429. isin    move.l    a1,d0        ;final address of a1 to d0
  430.     popl    a1        ;initial address of a1 to a1
  431.     sub.l    a1,d0        ;calculate position of str1 in str2
  432.  
  433. insexit    movem.l    (sp)+,d1/a0-a1    ;restore stack (gruesome results otherwise)
  434.     rts            ;that's it
  435.  
  436.     ENDC    ;ins
  437.  
  438.  
  439. **********************************************************************
  440. *
  441. *            cmpstr
  442. *
  443. * PURPOSE: compare two strings 
  444. *
  445. * ROUTINE TYPE: MACRO with subroutine
  446. *
  447. * SYNTAX: cmpstr <address of string>,<address of string>,terminator
  448. *
  449. * ENTRY CONDITIONS: None
  450. *
  451. * RETURNS: D0 = terminator if strings compare up to terminator
  452. *        first non comparing character of first operand
  453. *       A1 =    address of first non comparing character in 2nd operand
  454. *
  455. * USAGE: cmpstr    string1,string2,' '    ;space is end of string
  456. *     bne    nocompare        ;strings differ
  457. *     cmp    d0,(a1)            ;check for terminator in string1
  458. *     beq    samestrings        ;strings are identical
  459. *     bne    substringok        ;string1 is a substring of string2
  460. *
  461. * NOTE: This routine is a fairly general one, and may be used in many
  462. *    ways.  If the lengths of the string are not known, you might
  463. *    
  464. *    
  465. *
  466. **********************************************************************
  467.  
  468.     IFD    scm
  469.  
  470. strcmp    MACRO
  471.     lea    \1,a0        ;address of first string
  472.     lea    \2,a1        ;address of second string
  473.     move.l    #\3,d1        ;terminator
  474.     jsr    strcomp        ;do compare
  475.     ENDM
  476.  
  477. strcomp    movem.l    d1/a0-a1,-(sp)    ;preserve addresses
  478.  
  479. cmloop    move.b    (a0)+,d0    ;get byte of first string
  480.     cmp.b    d0,d1        ;check for terminator
  481.     beq.s    cmprtn        ;branch if terminator (substring compares)
  482.                 ;perhaps entire string
  483.  
  484.     cmp.b    (a1)+,d0    ;compare to byte of second string
  485.     beq.s    cmloop        ;OK.. check next byte
  486.  
  487. cmprtn    movem.l    (sp)+,d1/a0-a1    ;restore addresses
  488.     rts
  489.  
  490.     ENDC    ;scm
  491.  
  492. **********************************************************************
  493. *
  494. *            strlen
  495. *
  496. * PURPOSE: To find the length of a string.
  497. *
  498. * ROUTINE TYPE: MACRO and SUBROUTINE
  499. *
  500. * SYNTAX: strlen <address of string>,terminator
  501. *
  502. * ENTRY CONDITIONS: None
  503. *
  504. * RETURNS: D0 = length of string
  505. *
  506. * USAGE: strlen string,0    ;0 is terminator, can be any value
  507. *     move.l    d0,lengthvar    ;store the length if needed
  508. *
  509. **********************************************************************
  510.  
  511.     IFD    sln
  512.  
  513. strlen    MACRO
  514.     lea    \1,a0
  515.     move.b    #\2,d0
  516.     jsr    slen
  517.     ENDM
  518.  
  519. slen    move.l    a0,a1
  520. slnloop    cmp.b    (a0)+,d0
  521.     bne    slnloop
  522.     sub.l    a1,a0
  523.     move.l    a0,d0
  524.     subq.l    #1,d0
  525.     rts
  526.  
  527.     ENDC    ;sln
  528.  
  529. **********************************************************************
  530. *
  531. *            regdata
  532. *
  533. * PURPOSE: Dump all registers to screen
  534. *
  535. * ROUTINE TYPE: SUBROUTINE
  536. *
  537. * SYNTAX: jsr regdump
  538. *
  539. * ENTRY CONDITIONS: None
  540. *
  541. * RETURNS: Dumps all regs (a0-a7, d0-d7) to screen
  542. *
  543. * USAGE: jsr regdump
  544. *
  545. **********************************************************************
  546.  
  547.     IFD    dbug
  548.  
  549. regdata    dc.b    ' D0: '
  550. d0d    dc.b    '00000000  '
  551.     dc.b    ' D1: '
  552. d1d    dc.b    '00000000  '
  553.     dc.b    ' D2: '
  554. d2d    dc.b    '00000000  '
  555.     dc.b    ' D3: '
  556. d3d    dc.b    '00000000',10
  557.     dc.b    ' D4: '
  558. d4d    dc.b    '00000000  '
  559.     dc.b    ' D5: '
  560. d5d    dc.b    '00000000  '
  561.     dc.b    ' D6: '
  562. d6d    dc.b    '00000000  '
  563.     dc.b    ' D7: '
  564. d7d    dc.b    '00000000',10,10
  565.     dc.b    ' A0: '
  566. a0d    dc.b    '00000000  '
  567.     dc.b    ' A1: '
  568. a1d    dc.b    '00000000  '
  569.     dc.b    ' A2: '
  570. a2d    dc.b    '00000000  '
  571.     dc.b    ' A3: '
  572. a3d    dc.b    '00000000',10
  573.     dc.b    ' A4: '
  574. a4d    dc.b    '00000000  '
  575.     dc.b    ' A5: '
  576. a5d    dc.b    '00000000  '
  577.     dc.b    ' A6: '
  578. a6d    dc.b    '00000000  '
  579.     dc.b    ' A7: '
  580. a7d    dc.b    '00000000',10,10
  581. endump    EQU    *-regdata
  582.  
  583.     CNOP    0,4
  584.  
  585. regdump    movem.l    d0-d7/a0-a7,-(sp)
  586.     popl    d0
  587.     binhex    d0,d0d
  588.     popl    d0
  589.     binhex    d0,d1d
  590.     popl    d0
  591.     binhex    d0,d2d
  592.     popl    d0
  593.     binhex    d0,d3d
  594.     popl    d0
  595.     binhex    d0,d4d
  596.     popl    d0
  597.     binhex    d0,d5d
  598.     popl    d0
  599.     binhex    d0,d6d
  600.     popl    d0
  601.     binhex    d0,d7d
  602.  
  603.     popl    d0
  604.     binhex    d0,a0d
  605.     popl    d0
  606.     binhex    d0,a1d
  607.     popl    d0
  608.     binhex    d0,a2d
  609.     popl    d0
  610.     binhex    d0,a3d
  611.     popl    d0
  612.     binhex    d0,a4d
  613.     popl    d0
  614.     binhex    d0,a5d
  615.     popl    d0
  616.     binhex    d0,a6d
  617.     popl    d0
  618.     binhex    d0,a7d
  619.     rts
  620.  
  621. shoregs    print    regdata,#endump
  622.     rts
  623.  
  624.     ENDC
  625.  
  626. **********************************************************************
  627. *
  628. *            leadspace
  629. *
  630. * PURPOSE: replace ASCII zeros with spaces
  631. *
  632. * ROUTINE TYPE: MACRO with SUBROUTINE
  633. *
  634. * SYNTAX: ldspc    stringaddr,terminator
  635. *
  636. * ENTRY CONDITIONS: String must be terminated with anything but 
  637. *            an ASCII '0' ($30)
  638. *
  639. * RETURNS: address of first non '0' (ASCII) byte
  640. *
  641. * USAGE: ldspc    buffer
  642. *
  643. **********************************************************************
  644.  
  645.     IFD    leadspc
  646.  
  647. ldspc    MACRO
  648.     move.l    #\1,a0        ;string address
  649.     bsr    doldspc
  650.     ENDM
  651.  
  652. doldspc    cmp.b    #'0',(a0)
  653.     bne    endldspc
  654.     move.b    #' ',(a0)+
  655.     bra    doldspc
  656. endldspc:
  657.     rts
  658.  
  659.     ENDC
  660.  
  661. **********************************************************************
  662. NOTES: The routines contained in this file were written to make things
  663. easier for me. They may not be to your liking, in which case you are
  664. invited to change them to suit your own way of looking at things. In
  665. any case, please feel free to use them in any way you see fit.
  666.  
  667.    Larry Phillips, CIS - 76703,4322
  668.  
  669.